/*** 
 * @Author: Yanan Chen
 * @Date: 2021-11-02 13:47:26
 * @LastEditTime: 2021-12-16 15:19:53
 * @LastEditors: Yanan Chen
 * @Description: 
 * @FilePath: \sadwinner\fw\esp32\Src\APP\app_thread.h
 * @
 */

#ifndef PRJ_APP_THEREAD_H
#define PRJ_APP_THEREAD_H

#include "hal_function.h"
#include "app_base.h"



class NormalFSM : public AppFSM
{
public:
    NormalFSM(){};
    ~NormalFSM(){};
    void enter();
    void exit();
    void run(void *arg);
};

class SleepFSM : public AppFSM
{
public:
    SleepFSM(){};
    ~SleepFSM(){};
    void enter();
    void exit();
    void run(void *arg);
};

class AppThread
{
public:
    AppThread();
    ~AppThread(){};

    void init();
    void process();
    void modeJump(RunMode mode);
    //message
    void loadConfig(void);
    static int sendMessage(MessageHandle *m);
    static void threadCreate();
    
private:
    static TaskHandle_t  taskHandle;
    static TimerHandle_t timerHandle;
    static void thread(void *a);
    static void threadtimeCallback(TimerHandle_t handle);
    static QueueHandle_t messageQueue;
    MessageHandle message;
    void setmode(RunMode mode);
    void create_thread();
    RunMode mode;
    SleepFSM sleep;
    NormalFSM normal;
    AppFSM *fsm;
};


#endif